/**
 * Created by ZFL on 2017/9/27.
 */
var talentId;
var app;
function appInit(){
    PageInit()
}
function PageInit() {
    expectDetail();

}

Vue.filter('appDivide', function(value) {
    return fmoneyStr(divideNumber(value,100));
});
function  openAllGoods() {
    $('.recommend-wrap').removeClass('back-show');
    $('.all-goods').addClass('back-show');
}
function selectGoods() {
    $('.recommend-wrap').addClass('back-show');
    $('.all-goods').removeClass('back-show ');
}

//加载普通期详情
function expectDetail() {
    $.ajaxHandler({
        model: function () {
            var obj = {};
            if (com_obj.userId) {
                obj.userId = com_obj.userId;
            } else {
                obj.userId = 0;
            }
            obj.serialId = $.getPara("serialId");
            return obj;
        },
        visibleTime: 0,
        visible: 'show',
        approve: true,
        api: "yg_baijiaapp/serial/nomalSrialDetail",
        success: function (result) {
            if (result.code == 10000) {
                var data = result.data;
                var obj ={};
                obj.coverImgpath =data.coverImgpath;//期封面图
                obj.serialId = data.serialId;//期ID
                obj.title = data.title; //期标题
                document.title = data.title;
                //详情图
                var serialContentImages =[];
                $.each(data.serialContentImages,function (j,rows) {
                    var serObj = {};
                    serObj.imagePath = rows.imagePath; //详情图地址
                    serObj.imgHeight = rows.imgHeight;
                    serObj.imgWidth = rows.imgWidth;
                    serObj.jumpStyle = rows.jumpStyle;
                    serObj.jumpTo = rows.jumpTo;
                    if(rows.jumpStyle == 1){//1不跳转，2跳转到商品详情页，3跳转到H5，4跳转到另一期的详情页
                        serObj.hrefLink = 'javascript:;';
                    }else if(rows.jumpStyle == 2){
                        serObj.hrefLink = '/b2c/goods/goods.html?goodsId='+rows.jumpTo+'&talentId='+$.getPara("talentId");
                    }else if(rows.jumpStyle == 3){
                        serObj.hrefLink = '/';
                    }else if(rows.jumpStyle == 4){
                        serObj.hrefLink = '/b2c/serial/serial.html?serialId='+rows.jumpTo+'';
                    }
                    serObj.orderNo =  rows.orderNo;
                    serObj.serialContentId =  rows.serialContentId;
                    serObj.serialId =  rows.serialId;
                    serialContentImages.push(serObj);
                });
                obj.serialContentImages = serialContentImages;
                //关联商品
                var goodsList =[];
                var goods =[];
                $.each(data.goodsList,function (j,rows) {
                    var gObj = {};
                    gObj.goodsChannel = rows.goodsChannel; //商品进货渠道 1电商；2门店；3海淘
                    gObj.goodsId = rows.goodsId;//商品ID
                    gObj.goodsImage = rows.goodsImage;//商品图片
                    gObj.isYiYe = rows.isYiYe; //是否是异业 0：自营 1：异业 2：海淘
                    gObj.labelName = rows.labelName;  //标签
                    gObj.lowestPrice =  rows.lowestPrice;
                    gObj.name =  rows.name;//商品名称
                    gObj.suggestedPrice =  rows.suggestedPrice;//市场价
                    gObj.talentLimit =  rows.talentLimit; //达人佣金比例  百分单位
                    gObj.href = '/b2c/goods/goods.html?goodsId='+rows.goodsId+'&talentId='+$.getPara("talentId");
                    goodsList.push(gObj);
                    if(j<4){
                        goods.push(gObj);
                    }
                });
                var mWidth =9.2;
                var _width = 2.7466*(goodsList.length+1)+0.2*(goodsList.length+2);
                if(_width>mWidth){
                    mWidth =_width;
                }
                obj.mWidth = {width:''+mWidth+'rem'};
                obj.goodsList =goodsList;
                obj.goods =goods;
                app = new Vue({
                    el: '#recommendApp',
                    data: {
                        app:obj
                    },
                    // 在 `methods` 对象中定义方法
                    methods: {
                        greet: function (event) {
                            // `this` 在方法里指当前 Vue 实例
                            //alert('Hello ' + this.name + '!');
                            // `event` 是原生 DOM 事件
                            if (event) {
                                //alert(event.target.tagName);
                            }
                        }
                    }
                });

            } else {
                $.toast("加载期详情失败","text");
            }
        }
    });
}

//分享期详情、分享达人期详情
function shareExpect() {
    $.ajaxHandler({
        model: function () {
            var obj = {};
            obj.shareSerialId=$.getPara("shareSerialId");
            return obj;
        },
        visibleTime: 0,
        visible: 'show',
        approve: true,
        api: "yg_baijiaapp/serial/getShare",
        success: function (result) {
            if (result.code == 10000) {
                var data = result.data;
                var obj ={};
                obj.agio = data.agio;//分佣类型  1 零佣； 2半佣； 3 全拥
                obj.coverImgpath =data.coverImgpath;//期封面图
                obj.serialId = data.serialId;//期ID
                obj.title = data.title; //期标题
                document.title = data.title;
                //详情图
                var serialContentImages =[];
                $.each(data.resContent,function (j,rows) {
                    var serObj = {};
                    serObj.imagePath = rows.imagePath; //详情图地址
                    serObj.imgHeight = rows.imgHeight;
                    serObj.imgWidth = rows.imgWidth;
                    serObj.jumpStyle = rows.jumpStyle;
                    serObj.jumpTo = rows.jumpTo;
                    if(rows.jumpStyle == 1){
                        serObj.hrefLink = 'javascript:;';
                    }else if(rows.jumpStyle == 2){
                        serObj.hrefLink = '/b2c/goods/goods.html?goodsId='+rows.jumpTo+'&talentId='+$.getPara("talentId");
                    }else if(rows.jumpStyle == 3){
                        serObj.hrefLink = '/';
                    }else if(rows.jumpStyle == 4){
                        serObj.hrefLink = '/b2c/serial/serial.html?serialId='+rows.jumpTo+'&talentId='+$.getPara("talentId");
                    }
                    serObj.orderNo =  rows.orderNo;
                    serObj.serialContentId =  rows.serialContentId;
                    serObj.serialId =  rows.serialId;
                    serialContentImages.push(serObj);
                });
                obj.serialContentImages = serialContentImages;
                //关联商品
                var goodsList =[];
                var goods =[];
                $.each(data.goodsList,function (j,rows) {
                    var gObj = {};
                    gObj.goodsChannel = rows.goodsChannel; //商品进货渠道 1电商；2门店；3海淘
                    gObj.goodsId = rows.goodsId;//商品ID
                    gObj.goodsImage = rows.goodsImage;//商品图片
                    gObj.isYiYe = rows.isYiYe; //是否是异业 0：自营 1：异业 2：海淘
                    gObj.labelName = rows.labelName;  //标签
                    gObj.lowestPrice =  rows.lowestPrice;
                    gObj.name =  rows.name;//商品名称
                    gObj.suggestedPrice =  rows.suggestedPrice;//市场价
                    gObj.talentLimit =  rows.talentLimit; //达人佣金比例  百分单位
                    gObj.href = '/b2c/goods/goods.html?goodId='+rows.goodsId+'&talentId='+$.getPara("talentId")+'&agio='+data.agio+'';
                    goodsList.push(gObj);
                    if(j<4){
                        goods.push(gObj);
                    }
                });
                var mWidth =9.2;
                var _width = 2.7466*(goodsList.length+1)+0.2*(goodsList.length+2);
                if(_width>mWidth){
                    mWidth =_width;
                }
                obj.mWidth = {width:''+mWidth+'rem'};
                obj.goodsList =goodsList;
                obj.goods =goods;
                app = new Vue({
                    el: '#recommendApp',
                    data: {
                        app:obj
                    },
                    // 在 `methods` 对象中定义方法
                    methods: {
                        greet: function (event) {
                            // `this` 在方法里指当前 Vue 实例
                            //alert('Hello ' + this.name + '!');
                            // `event` 是原生 DOM 事件
                            if (event) {
                                //alert(event.target.tagName);
                            }
                        }
                    }
                });

            } else {
                $.toptip(result.message,"error");
                $("#recommendApp").hide();
            }
        }
    });
}





